package com.aitools.mcp.service;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

/**
 * Service class for handling MCP server calls and AI responses.
 * Implements AiService interface to provide AI response generation functionality.
 */
@Service
public class TaskMcpCallServerServices implements AiService {
    private final ChatClient chatClient;

    /**
     * Constructs a new TaskMcpCallServerServices instance.
     * @param aiClientBuilder the ChatClient builder used to create the chat client
     */
    public TaskMcpCallServerServices(ChatClient.Builder aiClientBuilder) {
        this.chatClient = aiClientBuilder.build();
    }

    @Override
    /**
     * Gets AI response for the given prompt by calling the MCP server.
     * @param prompt the input prompt to send to the AI
     * @return ResponseEntity containing the AI response
     */
    public ResponseEntity<String> getAiResponse(String prompt) {
        String response = this.chatClient
                .prompt(prompt)
                .call()
                .content();
        return ResponseEntity.ok(response);
    }
}
